import request from "../request.ts"

export const getParentCategoriesApi = () => {
  return request({
    url: "/api/parent-category",
    method: "GET"
  })
}

/**
 *
 * @param id 大类别ID
 * @returns 数据集数组
 */
export const getSubCategoriesApi = (id: string) => {
  return request({
    url: "/api/child-category/" + id,
    method: "GET"
  })
}

//管理员

/**
 *
 * @param name 新大类别名称
 * @returns
 */
export const createParentCategoryApi = (name: string) => {
  return request({
    url: "/admin/api/parent-category",
    method: "POST",
    data: {
      name
    }
  })
}

/**
 *
 * @param name 新数据集名称
 * @param parentCategoryId 所属大类别ID
 * @returns
 */
export const createSubCategoryApi = (name: string, parentCategoryId: number) => {
  return request({
    url: "/admin/api/child-category",
    method: "POST",
    data: {
      name,
      p_class_id: parentCategoryId
    }
  })
}

/**
 *
 * @param categoryId 数据集ID
 * @returns
 */
export const deleteSubCategoryApi = (categoryId: number) => {
  return request({
    url: "/admin/api/child-category",
    method: "DELETE",
    params: {
      category: categoryId
    }
  })
}
